//https://www.acwing.com/activity/content/introduction/3043/group_buy/138937/
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(), m = scanner.nextInt();
        for(int i = 0; i <= 100 && m > 0; i++) {
            int remainder = m % n;
            if (remainder == 0 || remainder == 1 || remainder == n - 1){
                if(remainder != 1 && remainder == n - 1) {
                    m++;
                }
            }
            else {
                System.out.println("NO");
                return;
            }
            m /= n;
        }
        if(m == 0) {
            System.out.println("YES");
        }
    }
}
